import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isShowFooter: true,
    detailHeader: true,
    CityId: localStorage.getItem('CityId') || '',
    CityName: localStorage.getItem('CityName') || '',
    // 存储token
    token: localStorage.getItem('token') || '',
    userId: localStorage.getItem('userId') || ''
  },
  mutations: {
    // 存储城市id
    getCityId(state, CityId) {
      localStorage.setItem('CityId', CityId)
      state.CityId = CityId
    },
    // 存储城市名字
    getCityName(state, CityName) {
      localStorage.setItem('CityName', CityName)
      state.CityName = CityName
    },
    // 存储用户id
    setUserId(state, userId) {
      localStorage.setItem('userId', userId)
      state.userId = userId
    },
    // 存储token
    setToken(state, token) {
      localStorage.setItem('token', token)
      state.token = token
    },
    // 定义方法-修改state中的数据，控制true和false
    show(state) { //  显示
      state.isShowFooter = true
    },
    hide(state) { //  隐藏
      state.isShowFooter = false
    },
    yin(state) {
      state.detailHeader = false
    },
    xian(state) {
      state.detailHeader = true
    }
  },
  actions: {
  },
  modules: {
  }
})
